﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/getSecondToStart")]
	public class GetSecondToStartController : ControllerBase
	{
		[HttpPost]
		public IActionResult GetSecondToStart([FromForm] GetSecondToStartModel model)
		{
			Round round = new Round(model.round_id);
			Group group = new Group(round.GroupId);
			Event @event = new Event(group.event_id);
			if (string.IsNullOrEmpty(@event.db_name))
			{
				return Ok(new ErrorResponse { status = -1, errmsg = "The game does not exist" });
			}
			long now = Tools.GetTimestamp();
			long secondToStart = @event.start_time - now;
			return Ok(new GetSecondToStartResponse { status = 1, second = secondToStart });
		}
		public class GetSecondToStartModel
		{
			public int round_id { get; set; }
		}
		public class GetSecondToStartResponse
		{
			public int status { get; set; }
			public long second { get; set; }
		}
	}
}
